#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
vector<int>a(0);
vector<bool>c(0);
ll ans1=0;
void dfs(int x){
    if(x==n-1){
        ll ans=0;
        int lr=0,lb=0;
        c[x]=0;
        for(int i=0;i<n;i++){
            if(!(lr==0&&c[i]==0)&&!(lb==0&&c[i]==1)){
                if(c[i]==0){
                    if(a[i]==lr){
                        ans+=lr;
                        lr=a[i];
                    }
                }
                else if(c[i]==1){
                    if(a[i]==lb){
                        ans+=lb;
                        lb=a[i];
                    }
                }
            }
            if(c[i]==0)lr=a[i];
            if(c[i]==1)lb=a[i];
        }
        ans1=max(ans1,ans);
        ans=0;
        c[x]=1;
        lr=0,lb=0;
        for(int i=0;i<n;i++){
            if(!(lr==0&&c[i]==0)&&!(lb==0&&c[i]==1)){
                if(c[i]==0){
                    if(a[i]==lr){
                        ans+=lr;
                        lr=a[i];
                    }
                }
                else if(c[i]==1){
                    if(a[i]==lb){
                        ans+=lb;
                        lb=a[i];
                    }
                }
            }
            if(c[i]==0)lr=a[i];
            if(c[i]==1)lb=a[i];
        }
        ans1=max(ans1,ans);
        ans=0;
    }
    else{
        c[x]=0;
        dfs(x+1);
        c[x]=1;
        dfs(x+1);
    }
}
void solve(){
    ans1=0;
    cin>>n;a.clear();c.clear();
    a.resize(n);c.resize(n);
    for(int i=0;i<n;i++)cin>>a[i];
    dfs(0);
    cout<<ans1<<endl;

}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;cin>>t;
    while(t--)solve();
    return 0;
}
